<template>
  <div class="home">
    <el-container class="out_con">
      <!-- 给homeAside传值，传token -->
      <el-aside>
        <homeAside :userdata="{ tokenTo, userData }" />
      </el-aside>
      <el-container>
        <el-header><homeHeader></homeHeader></el-header>
        <el-main><router-view :token="token"></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import axios from "axios";
import homeAside from "./components/homeAside.vue";
import homeHeader from "./components/homeHeader.vue";

export default {
  name: "HomeIndex",
  data() {
    return {
      // 向下传token，才能实现用户的功能
      token: "",
      tokenTo: "",
      // 个人信息
      userData: {},
    };
  },
  components: {
    homeAside,
    homeHeader,
  },
  mounted() {
    // 获取token
    this.token = this.$store.state.token;
    this.tokenTo = this.token;
    // 获取用户信息
    var that = this;
    axios({
      method: "get",
      url: "http://q.gcuweb.cn:8081/my/userinfo",
      async: false,
      headers: {
        Authorization: this.token,
      },
    })
      .then((res) => {
        // 返回用户的信息
        that.userData = res.data.data;
      })
      .catch((err) => {
        console.log("发生错误", err);
      });
  },
};
</script>

<style lang="less" scoped>
.home {
  height: 100%;
  .out_con {
    height: 100%;
    .el-aside {
      height: 100%;
    }
    .el-header {
      padding: 0px;
      height: 100%;
    }
    .el-main {
      padding: 0;
      height: 100%;
    }
  }
}
</style>
